package com.ahm.service.impl;

import com.ahm.pojo.Order;
import com.ahm.pojo.Product;
import com.ahm.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author anhaimeng
 * @title: OrderServiceImpl
 * @projectName consule-demo
 * @description: TODO
 * @date 2021/10/1916:24
 */
/*功能描述
 * @author ahm
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private RestTemplate restTemplate;


    @Override
    public Order selectOrderById(Integer id) {
        return new Order(id,"order=001","中国",22.0D,selectProductListByLoadBalancerAnnotation());
    }

    private List<Product> selectProductListByLoadBalancerAnnotation() {

        ResponseEntity<List<Product>> resp = restTemplate.exchange("http://service-provider/product/list", HttpMethod.GET, null, new ParameterizedTypeReference<List<Product>>() {
        });

        return  resp.getBody();

    }
}

